//
//  AppClient.m
//  TDE
//
//  Created by ceo on 2017/7/13.
//  Copyright © 2017年 chengb. All rights reserved.
//

#import "AppClient.h"
#import "APIClient.h"
@implementation AppClient

+ (instancetype)shared{
    
    static dispatch_once_t onceToken;
    static AppClient *shareInstance = nil;
    dispatch_once(&onceToken, ^{
        shareInstance = [[AppClient alloc]init];
    });
    
    return shareInstance;
}





- (void)loginWith:(LoginRequest *)params{
    
    [APIClient loginWith:params progress:^(NSProgress *progress) {
        
    } success:^(ApiResponse *response) {
        
       int code = [response.data[@"code"] intValue];
        if (code == 200) {
            self.currentUser = [[UserInfo alloc]init];
            self.currentUser.token = response.data[@"user_token"];
            
             [[NSNotificationCenter defaultCenter] postNotificationName:AppClientNOTI_LOGIN_SUCEESS object:response];
        }else{
             [[NSNotificationCenter defaultCenter] postNotificationName:AppClientNOTI_LOGIN_FAILE object:response];
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        [[NSNotificationCenter defaultCenter] postNotificationName:AppClientNOTI_LOGIN_FAILE object:error];
    }];

}



/**
 注册
 
 @param name name description
 @param passwd passwd description
 
 */
- (void)regisetWith:(NSString *)name passwd:(NSString *)passwd{
    
}


/**
 登录
 
 @param name 用户名
 @param passwd 密码
 */
- (void) loginWith:(NSString *)name
            passwd:(NSString *)passwd{
    
}


/**
 退出登录 ,退出登录时候应该将相应的 用户信息清除，推送用用相关信息清除，融云聊天相关信息清除
 */
- (void) logout{
    
}


/**
 获取当前用户
 @return return value description
 */
- (UserInfo *)getCurrentUserInfo{
    return nil;
}



@end
